package com.harper.service;

import com.harper.domain.Product;
import com.harper.service.impl.ProductServiceFallBack;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 使用Fegin实现微服务调用
 *
 * value用于指定调用nacos下哪个微服务
 * fallback用于指定容错类
 */
@FeignClient(value = "service-product", fallback = ProductServiceFallBack.class)  //声明调用的提供者的name
public interface ProductService {

    //指定调用提供者的哪个方法
    //@FeignClient + @GetMapping 就是一个完整的请求路径 http://serviceproduct/product/{pid}
    @GetMapping(value = "/product/{pid}")
    Product findByPid(@PathVariable("pid") Integer pid);

    //减库存
    @RequestMapping("/product/reduceInventory")
    void reduceInventory(@RequestParam("pid") Integer pid, @RequestParam("num") int num);

}
